# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=kopia
pkgver=0.17.0
pkgrel=2
pkgdesc="Fast and secure backup tool"
url="https://kopia.io/"
license="Apache-2.0"
arch="all"
makedepends="go"
subpackages="$pkgname-bash-completion $pkgname-zsh-completion"
checkdepends="openssh-keygen"
source="
	https://github.com/kopia/kopia/archive/v$pkgver/kopia-$pkgver.tar.gz
	skip-docker-tests.patch
	fix-loongarch64-build.patch
	"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"
export CGO_ENABLED=1

build() {
	local _goldflags="
	-X github.com/kopia/kopia/repo.BuildVersion=$pkgver
	-X github.com/kopia/kopia/repo.BuildInfo=AlpineLinux
	-X github.com/kopia/kopia/repo.BuildGitHubRepo=kopia/kopia
	"
	go build -ldflags "$_goldflags"

	./kopia --completion-script-bash > $pkgname.bash
	./kopia --completion-script-zsh > $pkgname.zsh
}

check() {
	# XXX: end to end restore_test fails to get same buffer from backup
	# shellcheck disable=2046
	go test -timeout=30m \
		$(go list -tags testing ./... | grep -Ev 'end_to_end_test')
}

package() {
	install -Dm755 kopia -t "$pkgdir"/usr/bin/

	install -Dm644 $pkgname.bash "$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -Dm644 $pkgname.zsh "$pkgdir"/usr/share/zsh/site-functions/_$pkgname
}

sha512sums="
950e1259cf84d87861736098b332059c92f475659f184c81c9644ff1491655f1a95e59700fd97b5889079c6842761cee6e090a46637381f513461e3d416dee3c  kopia-0.17.0.tar.gz
6c1c8ca52d83c940c561f11adc18298147882b709810edd8c6560c8988ff1bd30dae2adba4c18055d283e7c2c655a6c6f10c3951829826d6fe5eea20c8cb821d  skip-docker-tests.patch
d24108fe743032ef66c6037d6e4323410140fbcc5bc6efee9f7be5f876df6235d9dffebfa36aaba6e2fedb7fbf19c43913c3e3563506ae9cbbbb9a38998477e0  fix-loongarch64-build.patch
"
